using AndyPike.Unfuddle.Contracts;
using AndyPike.Unfuddle.Entities.Tickets;
using AndyPike.Unfuddle.Exceptions;
using NUnit.Framework;

namespace AndyPike.Unfuddle.Tests.Unit.Entities.Tickets
{
    [TestFixture]
    public class When_validating_a_ticket
    {
        [Test]
        public void Should_validate_a_vaild_ticket_when_creating()
        {
            var project = new Ticket
            {
                Id = 0,
                ProjectId = 1,
                Summary = "A summary"
            };
            project.Validate(EntityValidationContext.Creating);
        }

        [Test]
        public void Should_validate_a_vaild_ticket_when_updating()
        {
            var project = new Ticket
            {
                Id = 1,
                ProjectId = 1,
                Summary = "A summary"
            };
            project.Validate(EntityValidationContext.Updating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_ticket_id_is_not_0_when_creating()
        {
            var invalidProject = new Ticket { Id = 1, ProjectId = 1, Summary = "A summary" };
            invalidProject.Validate(EntityValidationContext.Creating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_ticket_id_is_not_1_when_updating()
        {
            var invalidProject = new Ticket { Id = 0, ProjectId = 1, Summary = "A summary" };
            invalidProject.Validate(EntityValidationContext.Updating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_ticket_summary_is_null()
        {
            var invalidProject = new Ticket { Id = 0, ProjectId = 1, Summary = null };
            invalidProject.Validate(EntityValidationContext.Creating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_ticket_summary_is_empty()
        {
            var invalidProject = new Ticket { Id = 0, ProjectId = 1, Summary = string.Empty };
            invalidProject.Validate(EntityValidationContext.Creating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_project_id_is_less_than_1()
        {
            var invalidProject = new Ticket { Id = 0, ProjectId = 0, Summary = string.Empty };
            invalidProject.Validate(EntityValidationContext.Creating);
        }
    }
}